<template>
  <common-page title="索引管理">
    <el-button slot="header" @click="back">返回</el-button>
    <common-list slot="content">
      <common-table v-loading="loading" :data="list">
        <el-table-column label="索引名称" align="left" prop="indexName">
          <template slot-scope="{ row }">{{ row.indexName }}</template>
        </el-table-column>

        <el-table-column
          label="索引前缀"
          align="left"
          prop="indexPrefix"
          show-overflow-tooltip
        >
          <template slot-scope="{ row }">{{ row.indexPrefix || "-" }}</template>
        </el-table-column>
        <el-table-column label="索引类型" align="left" prop="indexType">
          <template slot-scope="{ row }">{{ row.indexType || "-" }}</template>
        </el-table-column>

        <el-table-column label="时间格式" align="left" prop="dateFormat">
          <template slot-scope="{ row }">{{ row.dateFormat || "-" }}</template>
        </el-table-column>

        <!-- <el-table-column label="组件数据源" align="left" prop="isShow">
        <template slot-scope="{row}">
          <el-switch v-model="row.isShow" :active-value="1" :inactive-value="0">
          </el-switch>
        </template>
      </el-table-column> -->

        <el-table-column label="操作" align="left" width="147">
          <template slot-scope="{ row }">
            <el-button type="text" @click="synchronization(row)"
              >同步</el-button
            >
            <el-button type="text" @click="config(row)">字段配置</el-button>
            <!--v-hasPermi="['system:index:columnlist']"-->
            <el-button type="text" @click="detail(row)">详情</el-button>
            <!--v-hasPermi="['system:index:detail']"-->
            <!--<el-button  type="text" hasPermi>自动关闭</el-button>-->
          </template>
        </el-table-column>
      </common-table>

      <configView
        ref="configView"
        :indexPrefix="indexPrefix"
        v-if="configView"
        @back="configView = false"
      />
      <detailView
        ref="detailView"
        v-if="detailView"
        @back="detailView = false"
      />
    </common-list>
    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList"
    />
  </common-page>
</template>

<script>
import configView from "./configView.vue";
import {
  repertory_list,
  syncFiledsByIndexPrix,
} from "@/api/management/echart/repertory";
import BaseList from "@/mixins/BaseList";
import detailView from "./detailView.vue";
export default {
  name: "repertoty",
  mixins: [BaseList],
  components: { configView, detailView },
  props: {},
  data() {
    return {
      configView: false,
      detailView: false,
      total: 1, // 总条数
      loading: false, // table 加载中
      list: [{ a: 1 }], // 数据列
      selectionIds: "", // 列表选中数据id
      single: true, // 非单个禁用
      multiple: true, // 非多个禁用
      query: {
        pageNum: 1,
        pageSize: 10,
      },
      id: "",
      row: null,
      indexPrefix: ""
    };
  },
  // 方法
  methods: {
    show(row) {
      this.row = row;
      this.getList(row);
      this.id = row.id;
    },
    back() {
      this.$emit("back");
    },
    /**
     * 获取列表
     */
    getList(row) {
      this.loading = true;
      let query = { ...this.query, ...row };
      repertory_list(query)
        .then((res) => {
          if (res && res.code === 200) {
            this.list = res.rows;
            this.total = res.total;
          } else {
            this.list = [];
            this.total = 0;
            this.handleListTips(res);
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    detail(row) {
      this.detailView = true;
      this.$nextTick(() => {
        this.$refs.detailView.show(row, this.id);
      });
    },
    config(row) {
      this.configView = true;
      this.indexPrefix = row.indexPrefix;
      this.$nextTick(() => {
        this.$refs.configView.show(row);
      });
    },
    synchronization(row) {
      const ids = {
        datasourceId: this.id,
        id: row.id,
      };
      syncFiledsByIndexPrix(ids).then((res) => {
        if (res && res.code === 200) {
          this.$GlobalSuccessMessage("操作成功");
        }
      });
    },
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
};
</script>
<style lang="scss" scoped></style>
